#include<stdio.h>
#include <sys/types.h>
#include<unistd.h>
#include<sys/wait.h>


int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //child
    printf("i am process,pid:%d,ppid:%d\n",getpid(),getppid());
    sleep(5);
    //这类方法的标准写法
    //ls -a -l
   // char* myargv[]={
   //   "ls",
   //   "-l",
   //   "-a",
   //   NULL
   // };
    // execl("/usr/bin/ls","ls","-a","-l",NULL);
    //execl("/usr/bin/ls","ls",NULL);
    //execlp("ls","ls","-a","-l",NULL);
    //execlp("top","top",NULL);
    //execv("/usr/bin/ls",myargv);
    //execvp("ls",myargv);
    //跨语言调用
    char*myargv[]={
      "otherExe",
      "-a",
      "-b",
      "-c",
      NULL
    }; 
    char* const myenv[]={
      "MYVAL=1111",
      "MYPATH=/user/bin/xxx",
      NULL
    };
    //execle("./otherExe","otherExe","-a","-w","-v",NULL,myenv);
    //execle("./otherExe","otherExe","-a","-w","-v",NULL,environ);
    //execv("./otherExe",myargv);
    //execl("/usr/bin/bash","bash","test.sh",NULL);
    execl("/usr/bin/python3","python3","test.py",NULL);
  }
  else if(id>0)
  {
    pid_t ret=waitpid(id,NULL,0);
    if(ret>0) printf("wait success,father pid:%d,ret id:%d\n",getppid(),ret);
    sleep(5);
  }

  return 0;
}
